package com.hotel.configs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Bean
    public WebMvcConfigurer crossConfiger(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")//允许服务器端的哪些url处理跨域
                        .allowedOrigins("*")//允许哪些请求域
                        .allowedMethods("*")//允许哪些请求方式
                        .allowedHeaders("*");//允许哪些请求头
                // exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(5);;
            }
        };
    }
}
